#-*- coding: utf-8 -*-

class User( object ):

	detailMsg = ""
	
	# 建構子
	def __init__( self, name, age ):
		self.name = name
		self.age  = age
	
	def getDetails( self ):
		detailMsg = "This is user's info\n"
		result	  = detailMsg + "Name: " + self.name + " ,Age: " + str( self.age ) + "\n"
		return result
		
	# 覆寫運算子
	def __str__( self ):
		result = self.getDetails()
		return result
	
	pass
# end of class User

prettyGirl = User( "Shakira", 21 )

# print prettyGirl + ""  # 執行異常! 因為沒有override User實體與Python字串的__add__()方法
print prettyGirl

def concatString( self, string ):
	result = self.__str__()
	return result

User.__add__ = concatString		# 在User類別外部，動態綁定一個函式，去覆寫User類別的__add__()方法

print prettyGirl + ""			# 會呼叫間接呼叫__str__()方法

ulgyGirl = None

# print ulgyGirl + ""			# 執行異常! 因為沒有override NoneType與Python字串的__add__()方法
print "result", ulgyGirl		# 印出None值

number = 1234
string = "ABCD"

# newString = number + string		# 執行異常，Python不會自動把數值物件轉換成字串!
newString = str( number ) + string	# 強制把number參考的物件轉換成Pyhton的字串，才能與其它字串concat!

if type( newString ) == str:
	print "newString is: ", newString

string 	  = "1000"
newNumber = number + int( string )  # 強制把string參考的物件轉換成Pyhton的數字，才能與其它數字進行加法運算

if type( newNumber ) == int:
	print "newNumber is: ", newNumber